package root.electronclass.electronclass.grade.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import root.electronclass.electronclass.R

/**
 *
 * @author Lokiy
 * @date 2024/4/20 12:55
 */
class CheckButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
    LinearLayout(context, attrs, defStyle) {

    var onCheckedChangeListener: OnCheckedChangeListener? = null

    var isChecked: Boolean = false
        set(value) {
            if (value != field) {
                field = value
                isSelected = field
                onCheckedChangeListener?.invoke(field)
            }
        }

    init {
        inflate(context, R.layout.view_check, this)
        findViewById<View>(R.id.yes).setOnClickListener {
            isChecked = true
        }
        findViewById<View>(R.id.no).setOnClickListener {
            isChecked = false
        }
//        if (background == null) {
//            setBackgroundResource(R.drawable.bg_round_white_border_dadcdf)
//        }
    }

}

typealias OnCheckedChangeListener = (isChecked: Boolean) -> Unit